<template>
  <a-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
          <a-tabs defaultActiveKey="1" @change="callback">
            <a-tab-pane tab="审批" key="1">
       <!-- <a-form-item label="流程" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'processId', validatorRules.processId]" placeholder="请输入流程"></a-input>
        </a-form-item>-->
<!--          0_贫困户贷款，1_企业贷款，2_带贫企业认定，3_带贫合作社认定-->
        <!--<a-form-item label="流程类别" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['approvalProcessType']" :trigger-change="true" dictCode="approval_process_type" placeholder="请选择流程类别"/>
        </a-form-item>-->
          
       <!-- <a-form-item label="流程步骤" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'approvalProcessCode', validatorRules.approvalProcessCode]" placeholder="请输入流程步骤"></a-input>
        </a-form-item>-->
        <a-form-item label="受理人" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'operator', validatorRules.operator]" placeholder="请输入受理人"></a-input>
        </a-form-item>
        <!--<a-form-item label="受理日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择受理日期" v-decorator="[ 'approvalProcessDate', validatorRules.approvalProcessDate]" :trigger-change="true" style="width: 100%"/>
        </a-form-item>-->
        <a-form-item label="回复内容" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-textarea v-decorator="['replyContent']" rows="4" placeholder="请输入回复内容"/>
        </a-form-item>
        <a-form-item label="相关资料" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-upload v-decorator="['information']" :trigger-change="true"></j-upload>
        </a-form-item>
<!--        0_通过，1_拒绝-->
        <!--<a-form-item label="状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['state']" :trigger-change="true" dictCode="state" placeholder="请选择状态"/>
        </a-form-item>-->
            </a-tab-pane>
            <a-tab-pane tab="流程" key="2" forceRender>
              <img  src="../../../../assets/pkh_process.png" alt="logo">
            </a-tab-pane>
          </a-tabs>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import JDate from '@/components/jeecg/JDate'  
  import JUpload from '@/components/jeecg/JUpload'
  import JDictSelectTag from "@/components/dict/JDictSelectTag"
  
  export default {
    name: "ProcessingModal",
    components: { 
      JDate,
      JUpload,
      JDictSelectTag,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"审批",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules:{
        processId:{},
        approvalProcessType:{},
        approvalProcessCode:{},
        approvalProcessDate:{},
        operator:{},
        replyContent:{},
        information:{},
        state:{},
        },
        url: {
          add: "/loanmanagement/processing/add",
          edit: "/loanmanagement/processing/edit",
        }
     
      }
    },
    created () {
    },
    methods: {
        callback(key) {
            console.log(key);
        },
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'processId','approvalProcessType','approvalProcessCode','approvalProcessDate','operator','replyContent','information','state'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'processId','approvalProcessType','approvalProcessCode','approvalProcessDate','operator','replyContent','information','state'))
      },
        showGoodsGallery1(record) {
            this.id = record.id;
            this.visible = true
        }
    }
  }
</script>